#!/bin/bash

# For all script types, returning an exit code of 0 (success) means the
# script execution completed successfully.
#
# Requirements scripts can have the following exit codes that
# influence how the Client will handle the Fileset:
#
# - 210: This exit code will cause the Fileset to be treated like the
#        installation was successful (unless another requirements script fails,)
#        but the Fileset will not be downloaded nor installed.
#
# - 220: This exit code will prevent the installation and cause the client to
#        stop retrying unless a manual action is made (verify, reinstall, etc.)
#        or the Fileset is updated.
#
# Returning any other exit code but 0 (e.g. 1 or -1) will be reported as a
# "Requirements Failure: Script" in the Client Info window and Fileset Report.
# This will also prevent the contents of the Fileset from downloading and
# installing. In this case, requirements scripts will be executed every 2
# minutes and the Fileset will be installed when they all return 0.
#
# For other types of scripts, any non-zero exit code (e.g. 1 or -1) will cause the
# Fileset installation to fail and a script failure to be reported.
#
# If the script finishes without returning an exit code, the exit code 0
# (success) is assumed by default.
#
# Add the contents of your script below:
sleep 30

/usr/libexec/PlistBuddy -c "Add :Security_PasswordStrength integer 3" /Library/Preferences/com.teamviewer.teamviewer.preferences.plist

/usr/libexec/PlistBuddy -c "Add :Security_Adminrights integer 1" /Library/Preferences/com.teamviewer.teamviewer.preferences.plist

/usr/libexec/PlistBuddy -c "Add :Always_Online integer 1" /Library/Preferences/com.teamviewer.teamviewer.preferences.plist

sleep 15

teamviewer=$(ps -xa | grep -i "TeamViewer_Service" | grep -v grep | awk {'print $1'})

kill -9 $teamviewer

exit 0
